Skip to content

Develop - #9

Merged
jimbrig merged 2 commits into
mainfrom
develop
Jun 9, 2026
Merged

jimbrig merged 2 commits into
mainfrom
develop

Conversation

@jimbrig

@jimbrig jimbrig commented Jun 9, 2026

Copy link
Copy Markdown
Owner

See #8 & #7

jimbrig added 2 commits June 9, 2026 14:47
…time activation

GDAL algorithms that embed python at runtime (e.g. gdal driver gpkg
validate) import the osgeo_utils package, which was missing from the
runtime bundle. Stage it from the GDAL source tree during the build
(version-locked to the built tag), carry it into the bundle under
python/, and prepend <gdal_home>/python to PYTHONPATH (session-scoped)
in activate_gdal_runtime(). Add testthat coverage and an end-to-end
gpkg validate smoke test in CI.

Closes #7
feat: bundle pure-python osgeo_utils and expose via PYTHONPATH at run…
@jimbrig jimbrig self-assigned this Jun 9, 2026
@jimbrig
jimbrig merged commit 497199d into main Jun 9, 2026
1 of 2 checks passed
@jimbrig
jimbrig deleted the develop branch June 9, 2026 19:02
@jimbrig
jimbrig restored the develop branch June 9, 2026 19:02

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for GDAL's embedded Python algorithms by bundling the pure-python osgeo_utils package and prepending its path to PYTHONPATH during runtime activation. The changes include updates to the runtime activation logic, documentation, build and collection scripts, and comprehensive unit tests. The review feedback suggests improving path normalization on Windows to robustly check for existing PYTHONPATH entries, and cleaning up target directories in the build and collection scripts before copying files to prevent merging with stale files.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread R/gdal_runtime.R
Comment on lines +220 to +226
if (dir.exists(python_dir)) {
py_parts <- strsplit(Sys.getenv("PYTHONPATH", unset = ""), path_sep, fixed = TRUE)[[1]]
py_parts <- py_parts[nzchar(py_parts)]
if (!python_dir %in% py_parts) {
Sys.setenv(PYTHONPATH = paste(c(python_dir, py_parts), collapse = path_sep))
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

On Windows, path comparisons can fail due to differences in case sensitivity or slash direction (e.g., C:/path/to/python vs c:\\path\to\python). To ensure robust detection of existing PYTHONPATH entries and avoid duplicate or redundant additions, normalize both python_dir and py_parts (using tolower() and normalizePath()) before performing the %in% check.

  if (dir.exists(python_dir)) {
    py_parts <- strsplit(Sys.getenv("PYTHONPATH", unset = ""), path_sep, fixed = TRUE)[[1]]
    py_parts <- py_parts[nzchar(py_parts)]
    norm_python_dir <- tolower(normalizePath(python_dir, winslash = "/", mustWork = FALSE))
    norm_py_parts <- tolower(normalizePath(py_parts, winslash = "/", mustWork = FALSE))
    if (!norm_python_dir %in% norm_py_parts) {
      Sys.setenv(PYTHONPATH = paste(c(python_dir, py_parts), collapse = path_sep))
    }
  }

Comment thread tools/build_gdal.sh
Comment on lines +105 to +106
mkdir -p "${INSTALL_DIR}/python"
cp -r "${SRC_DIR}/swig/python/gdal-utils/osgeo_utils" "${INSTALL_DIR}/python/"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If a previous build has already staged osgeo_utils in ${INSTALL_DIR}/python/osgeo_utils, running cp -r can merge new files with old/stale files from previous builds. To ensure a clean and reliable build, remove any existing osgeo_utils directory before copying.

Suggested change
mkdir -p "${INSTALL_DIR}/python"
cp -r "${SRC_DIR}/swig/python/gdal-utils/osgeo_utils" "${INSTALL_DIR}/python/"
mkdir -p "${INSTALL_DIR}/python"
rm -rf "${INSTALL_DIR}/python/osgeo_utils"
cp -r "${SRC_DIR}/swig/python/gdal-utils/osgeo_utils" "${INSTALL_DIR}/python/"

Comment thread tools/collect_dlls.sh
Comment on lines +52 to +53
mkdir -p "${BUNDLE_DIR}/python"
cp -r "${INSTALL_DIR}/python/." "${BUNDLE_DIR}/python/"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent stale files from previous bundling attempts from persisting in the final bundle, it is safer to remove the existing ${BUNDLE_DIR}/python directory before recreating it and copying the new files.

Suggested change
mkdir -p "${BUNDLE_DIR}/python"
cp -r "${INSTALL_DIR}/python/." "${BUNDLE_DIR}/python/"
rm -rf "${BUNDLE_DIR}/python"
mkdir -p "${BUNDLE_DIR}/python"
cp -r "${INSTALL_DIR}/python/." "${BUNDLE_DIR}/python/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant